package com.iwuke.dance.http_request;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.iwuke.dance.wallet.bean.ECoinTopUpBean;
import com.iwuke.dance.wallet.bean.ETransactionRecordBean;
import com.iwuke.dance.wallet.bean.ListETransactionRecordBean;
import com.iwuke.dance.wallet.bean.QueryWalletBean;
import com.iwuke.dance.wallet.bean.RechargeEBalanceBean;
import com.iwuke.dance.wallet.mind_value.MindValueDetailsBean;
import com.iwuke.dance.wallet.starlight_value.starlight_value_bean.StarlightTransactionRecordBean;
import com.iwuke.dance.wallet.starlight_value.starlight_value_bean.StarlightTransactionRecordHomepageBean;
import com.iwuke.dance.wxapi.WXOpenBusinessViewBean;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;

public class BaseDataPase {

    public static BaseDataBean<Bean> getBean(String response){

        BaseDataBean<Bean> dataBean = new BaseDataBean<>();

        try {
            String dataString = DataPase.getDataString(response, dataBean);
            Bean bean = new Gson().fromJson(dataString, Bean.class);
            dataBean.dataBean = bean;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }

        return dataBean;
    }

    public static BaseDataBean<Bean> getBean2(String response){

        BaseDataBean<Bean> dataBean = new BaseDataBean<>();

        try {
            String dataString = DataPase.getDataString(response, dataBean);
            if (dataString!=null&&dataString.length()<3){
                Bean bean = new Bean();
                bean.id = Long.parseLong(dataString);
                dataBean.dataBean = bean;
            }else {
                dataBean.dataBean = null;
            }

        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }

        return dataBean;
    }


    public static BaseDataBean<QueryWalletBean> getQueryWalletBean(String response) {
        BaseDataBean<QueryWalletBean> dataBean = new BaseDataBean<>();

        try {
            String dataString = DataPase.getDataString(response, dataBean);
            QueryWalletBean bean = new Gson().fromJson(dataString, QueryWalletBean.class);
            dataBean.dataBean = bean;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }

        return dataBean;
    }

    public static BaseDataBean<RechargeEBalanceBean> getRechargeEBalanceBean(String response) {
        BaseDataBean<RechargeEBalanceBean> dataBean = new BaseDataBean<>();

        try {
            String dataString = DataPase.getDataString(response, dataBean);
            RechargeEBalanceBean bean = new Gson().fromJson(dataString, RechargeEBalanceBean.class);
            dataBean.dataBean = bean;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }

        return dataBean;
    }

    public static BaseDataBean<ECoinTopUpBean> getRechargeConfigBean(String response) {

        BaseDataBean<ECoinTopUpBean> vehicleModelBean = new BaseDataBean<>();
        try {
            String dataString = DataPase.getDataString(response, vehicleModelBean);
            //TrafficFlowBean dataBean = new Gson().fromJson(dataString, TrafficFlowBean.class);
            List<ECoinTopUpBean> dataList = new Gson().fromJson(dataString, new TypeToken<List<ECoinTopUpBean>>() {
            }.getType());
            vehicleModelBean.dataList = dataList;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }
        return vehicleModelBean;
    }

    public static BaseDataBean<ETransactionRecordBean> getETransactionRecordBean(String response) {
        BaseDataBean<ETransactionRecordBean> dataBean = new BaseDataBean<>();

        try {
            String dataString = DataPase.getDataString(response, dataBean);
//            Map<String, ETransactionRecordBean> map = new HashMap<>();
//            ETransactionRecordBean bean = new Gson().fromJson(dataString, ETransactionRecordBean.class);
//            Map<String, ETransactionRecordBean> bean = new Gson().fromJson(dataString,new TypeToken>(){}.getType());
            // 创建Gson对象
            Gson gson = new Gson();
            // 定义HashMap类型
            Type type = new TypeToken<HashMap<String, ETransactionRecordBean>>(){}.getType();

            // 解析JSON字符串到HashMap
            HashMap<String, ETransactionRecordBean> map = gson.fromJson(dataString, type);

            dataBean.dataMap = map;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }

        return dataBean;

    }

    public static BaseDataBean<ListETransactionRecordBean> getListETransactionRecordBean(String response) {

        BaseDataBean<ListETransactionRecordBean> vehicleModelBean = new BaseDataBean<>();
        try {
            String dataString = DataPase.getDataString(response, vehicleModelBean);
            //TrafficFlowBean dataBean = new Gson().fromJson(dataString, TrafficFlowBean.class);
            List<ListETransactionRecordBean> dataList = new Gson().fromJson(dataString, new TypeToken<List<ListETransactionRecordBean>>() {
            }.getType());
            vehicleModelBean.dataList = dataList;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }
        return vehicleModelBean;

    }

    public static BaseDataBean<StarlightTransactionRecordHomepageBean> getStarlightTransactionRecordHomepageBean(String response) {
        BaseDataBean<StarlightTransactionRecordHomepageBean> vehicleModelBean = new BaseDataBean<>();
        try {
            String dataString = DataPase.getDataString(response, vehicleModelBean);
            List<StarlightTransactionRecordHomepageBean> dataList = new Gson().fromJson(dataString, new TypeToken<List<StarlightTransactionRecordHomepageBean>>() {
            }.getType());
            vehicleModelBean.dataList = dataList;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }
        return vehicleModelBean;

    }

    public static BaseDataBean<StarlightTransactionRecordBean> getStarlightTransactionRecordBean(String response) {

        BaseDataBean<StarlightTransactionRecordBean> vehicleModelBean = new BaseDataBean<>();
        try {
            String dataString = DataPase.getDataString(response, vehicleModelBean);
            List<StarlightTransactionRecordBean> dataList = new Gson().fromJson(dataString, new TypeToken<List<StarlightTransactionRecordBean>>() {
            }.getType());
            vehicleModelBean.dataList = dataList;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }
        return vehicleModelBean;

    }

    public static BaseDataBean<WXOpenBusinessViewBean> getWXOpenBusinessViewBean(String response) {
        BaseDataBean<WXOpenBusinessViewBean> dataBean = new BaseDataBean<>();

        try {
            String dataString = DataPase.getDataString(response, dataBean);
            WXOpenBusinessViewBean bean = new Gson().fromJson(dataString, WXOpenBusinessViewBean.class);
            dataBean.dataBean = bean;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }

        return dataBean;

    }

    public static BaseDataBean<StarlightTransactionRecordHomepageBean> getStarlightTransactionRecordHomepage(String response) {
        BaseDataBean<StarlightTransactionRecordHomepageBean> dataBean = new BaseDataBean<>();

        try {
            String dataString = DataPase.getDataString(response, dataBean);
            StarlightTransactionRecordHomepageBean bean = new Gson().fromJson(dataString, StarlightTransactionRecordHomepageBean.class);
            dataBean.dataBean = bean;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }

        return dataBean;

    }

    public static BaseDataBean<MindValueDetailsBean> getMindValueDetailsBean(String response) {
        BaseDataBean<MindValueDetailsBean> dataBean = new BaseDataBean<>();

        try {
            String dataString = DataPase.getDataString(response, dataBean);
            MindValueDetailsBean bean = new Gson().fromJson(dataString, MindValueDetailsBean.class);
            dataBean.dataBean = bean;
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }

        return dataBean;
    }
}
